<template>
  <div class="region">
    <div class="content">
      <div class="left">地区：</div>
      <ul>
        <li :class="{active:RegFlag==''}" @click="changeRegion('')">全部</li>
        <li v-for="region in RegionArr" :key="region.value"  :class="{active:RegFlag==region.value}" @click="changeRegion(region.value)">{{region.name}}</li>
      </ul>
    </div>
  </div>
</template>
<script setup lang="ts">
import { reqHospitalLevelAndRegion } from "@/api/home";
import { onMounted, ref } from "vue";

//返回数据的接收类型
import type {
  HospitalLevelAndRegionResponseData,
  HospitalLevelAndRegionArr,
} from "@/api/home/type";


//存储地区的数据
let RegionArr = ref<HospitalLevelAndRegionArr>([]);
let RegFlag = ref<string>('')

//页面加载 挂载数据
onMounted(() => {
  getRegion();
});
const getRegion = async () => {
  let result: any = await reqHospitalLevelAndRegion("Beijin");
  let result2:HospitalLevelAndRegionResponseData = result.data;
  if(result2.code==200){
    RegionArr.value = result2.data;
  }
};

const changeRegion=(region:string)=>{
    RegFlag.value = region
}
</script>


<script lang="ts">
    export default {
        name:'Region'
    }
</script>



<style scoped lang="scss">
.region {
  color: #7f7f7f;
  margin-top: 10px;
  .content {
    display: flex;
    .left {
      margin-right: 10px;
      width: 50px;
    }
    ul {
      display: flex;
      flex-wrap: wrap;
      li {
        margin-right: 10px;
        margin-bottom: 10px;
        &.active {
          color: #55a6fe;
        }
      }

      li:hover {
        color: #55a6fe;
      }
    }
  }
}
</style>
